tongfusoft.taskDetail = function() {
}
tongfusoft.taskDetail.prototype = {

	returnBtn : function() {

		$("#returnBtn").click(function(){
			

			var params = {};
			params["taskDetailId"] = $("#taskDetailId").val();
			common.post('taskDetail/finish', params, function(data) {

				if (data.state == 'success') {
					document.location.href=common.getContextPath("task/upcoming?page");
				}else{
					alert("提交失败");
				}
			
			});
			
			
		
			
		});

	},
	upload:function(){
		
		$('#upFile').fileupload({
	  		 dataType: 'json',
	  		 done: function (e, data) {
	  			if(data.result.state=='success'){
	  				document.location.reload();
	  			}else{
	  				alert("上传失败");
	  			}
	  		 },
	  		 progressall: function (e, data) {
	  	       var progress = parseInt(data.loaded / data.total * 100, 10);
	  	       $('#Iprogress .bar').css(
	  	           'width',
	  	           progress + '%'
	  	       );
	  	   }
		});
	},
	query : function() {
		var params = {};
		params["taskDetailId"] = $("#taskDetailId").val();
		common.post('taskDetail?query', params, function(data) {

			if (data.state == 'success') {

				
				
				var uploadFileDiv='';
				
				uploadFileDiv=uploadFileDiv+'<span class="btn btn-success fileinput-button ">';
				uploadFileDiv=uploadFileDiv+'<i class="fa fa-fw fa-plus"></i><span>上传文件</span>';
				uploadFileDiv=uploadFileDiv+'<input  id="upFile" style="cursor: pointer;direction: ltr;font-size: 20px; margin: 0;opacity: 0; position: absolute;right: 0; top: 0;" type="file" name="file_upload" data-url="'+common.getContextPath("task/file/"+data.data.taskDetailId+"")+'" multiple=""/>';
				uploadFileDiv=uploadFileDiv+'</span>';
				
				$("#uploadFileDiv").html(uploadFileDiv);
				
				$.map(data.data, function(item, index) {

					if (index == 'taskTag') {

						var tagHtml = '';
						$.each(item.split(","), function(k, v) {
							if (v != '') {
								tagHtml = tagHtml + '	<span class="tag label label-info">' + v + '</span>';

							}
						})
						$("#taskTag").html(tagHtml);

					} else if (index == 'docList') {

						var docHtml = '';
						$.each(item, function(k, v) {
							var url = 'document/download/' + v.docId;
							docHtml = docHtml + '	<span><a docId="' + v.docId
									+ '" class="downloadBtn"  target="_blank" href="' + common.getContextPath(url)
									+ '">' + v.original + ';</a></span>';

						})
						$("#docList").html(docHtml);
					} else {

						$("#" + index).text(item);
					}

				});

			}
			var obj = new tongfusoft.taskDetail();
			obj.upload();
		});
		
	}

}

$(function() {

	var obj = new tongfusoft.taskDetail();
	obj.query();
	obj.returnBtn();

})